home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Developer / PTR-TCL v2.1 / 2) TCL Munger / DoLine.c next >
Encoding:
C/C++ Source or Header  |  1994-01-04  |  2.3 KB  |  130 lines  |  [TEXT/MMCC]

  1. /*
  2.  * DoLine.c
  3.  *
  4.  * Where all the action is
  5.  */
  6.  
  7. #include <ctype.h>
  8. #include <string.h>
  9. #include <stdio.h>
  10.  
  11. #define Boolean char
  12.  
  13. Boolean DoLine ( unsigned char * line ) ;
  14. void DoneLine ( void ) ;
  15.  
  16. static FILE * outfile = NULL ;
  17. static Boolean lastWas = 0 ;
  18.  
  19.  
  20. static unsigned char *
  21. space ( unsigned char * pos ) {
  22.  
  23.     while ( * pos && isspace ( * pos ) ) {
  24.         pos ++ ;
  25.     }
  26.     return pos ;
  27. }
  28.  
  29.  
  30. static char tok [ 100 ] ;
  31. static char new_name [ 100 ] ;
  32. static char old_name [ 100 ] ;
  33. Boolean isPrivate ;
  34.  
  35.  
  36. static unsigned char *
  37. nonspace ( unsigned char * pos ) {
  38.  
  39.     while ( * pos && ! isspace ( * pos ) ) {
  40.         pos ++ ;
  41.     }
  42.     return pos ;
  43. }
  44.  
  45.  
  46. static unsigned char *
  47. token ( unsigned char * pos ) {
  48.  
  49. unsigned char * npos ;
  50.  
  51.     pos = space ( pos ) ;
  52.     npos = nonspace ( pos ) ;
  53.     BlockMove ( pos , tok , npos - pos ) ;
  54.     tok [ npos - pos ] = 0 ;
  55.     return npos ;
  56. }
  57.  
  58.  
  59. static void
  60. output ( Boolean priv , char * newname , char * oldname , unsigned char * ret ) {
  61.  
  62.     if ( ! outfile ) {
  63.         outfile = fopen ( " CLASSLIST" , "w" ) ;
  64.     }
  65.     if ( outfile ) {
  66.         fprintf ( outfile , "%s %s %s\n" , newname , oldname , priv ?
  67.             "private" : "public" ) ;
  68.     }
  69.     sprintf ( ( char * ) ret , "DECLARE_%s ( %s , %s )\r" , priv ? "PRIVATE" : "PUBLIC" ,
  70.         newname , oldname ) ;
  71. }
  72.  
  73.  
  74. Boolean
  75. DoLine ( unsigned char * line ) {
  76.  
  77. unsigned char * ret = line + 1 ;
  78.  
  79.     isPrivate = 1 ;
  80.  
  81.     line [ 1 + * line ] = 0 ;
  82.     line ++ ;
  83.     line = token ( line ) ;
  84.     if ( ! * line && ! tok [ 0 ] ) {
  85.         return false ; /* Ignore empty lines */
  86.     }
  87.     if ( lastWas ) {
  88.         lastWas = 0 ;
  89.         if ( ! strcmp ( tok , "{" ) ) { /* Don't like trailing braces myself...*/
  90.             line [ -1 ] = ' ' ;
  91.             return true ;
  92.         }
  93.     }
  94.     if ( strcmp ( "class" , tok ) ) {
  95.         if ( strcmp ( "struct" , tok ) ) {
  96.             return 0 ;
  97.         }
  98.         isPrivate = 0 ;
  99.     }
  100.     line = token ( line ) ;
  101.     strcpy ( new_name , tok ) ;
  102.     line = token ( line ) ;
  103.     if ( strcmp ( ":" , tok ) ) {
  104.         return 0 ;
  105.     }
  106.     line = token ( line ) ;
  107.     if ( ! strcmp ( ( char * ) tok , "public" ) ) {
  108.         line = token ( line ) ;
  109.         isPrivate = 0 ;
  110.     } else if ( ! strcmp ( ( char * ) tok , "private" ) ) {
  111.         line = token ( line ) ;
  112.         isPrivate = 1 ;
  113.     }
  114.     strcpy ( old_name , tok ) ;
  115.     output ( isPrivate , new_name , old_name , ret ) ;
  116.     ret [ -1 ] = strlen ( ( char * ) ret ) ;
  117.     lastWas = 1 ;
  118.     return 1 ;
  119. }
  120.  
  121.  
  122. void
  123. DoneLine ( void ) {
  124.  
  125.     if ( outfile ) {
  126.         fclose ( outfile ) ;
  127.     }
  128. }
  129.  
  130.